//设置Cookie
function setCookie(name,value,day,path,domain,secure) {
    var strCookie="";
    //必须要有name和value
    if(name&&value){
        strCookie+=encodeURIComponent(name)+"="+encodeURIComponent(value)+";";
    }
    //设置有效时期
    if(typeof(day)=="number"){
        var date=new Date();
        date.setDate(date.getDate()+day);
        strCookie+="expires="+date+";";

    }
    //设置路径
    if(path){
        strCookie+="path"+path+";";
    }
    //设置域名
    if(domain){
        strCookie+="domain"+domain+";";
    }
    //必须使用https协议才能访问
    if(secure){
        strCookie+="secure";

    }
    return document.cookie=strCookie;
}
//获取所有Cookie
// [uname=长沙1804, aaa=bbbb, ccc=ddddd]
function getCookieAll(){

    var obj={};
    var cookieStr=decodeURIComponent(document.cookie);//所有的cookie
    var arrList=cookieStr.split(";");
    // [uname=长沙1804, aaa=bbbb, ccc=ddddd]
    for(var i=0;i<arrList.length;i++){
        var tmpArr=arrList[i].split("=")
        obj[tmpArr[0].trim()]=tmpArr[1]
        // [name,长沙1804]
        // [ aaa,bbbb]
    }
    return obj;
}
//获取name属性值
function getCookieByName(name) {
    var obj=getCookieAll();
    return obj[name];
}
//cookie的删除,有效时间 expires
function removeCookie(name) {
    var date=new Date();
    date.setDate(date.getDate()-1);
    document.cookie=encodeURIComponent(name)+"=;expires="+date.toUTCString();
}











